package com.qf.business.redenvlopes.listener;

import com.ken.event.action.apply.consumer.IKenEventHandler;
import com.ken.event.action.apply.consumer.KenEvent;
import com.ken.event.standard.entity.KenMessage;
import com.qf.business.redenvlopes.service.RedEnvlopesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 抢红包的事件处理
 * author Ken
 * create_time 2022/12/6
 */
@KenEvent("rob-red")
@Slf4j
public class RobRedHandler implements IKenEventHandler<Map<String, Long>> {

    @Autowired
    private RedEnvlopesService redEnvlopesService;

    @Override
    public void eventHandler(Map<String, Long> data, KenMessage kenMessage) {
        log.debug("[rob red event] 红包服务 - 接收到抢红包的事件 - {}", data);
        Long redid = data.get("redid");
        Long uid = data.get("uid");
        Long robScore = data.get("robScore");

        //执行抢红包的业务
        redEnvlopesService.robRed(redid, uid, robScore);
    }
}
